<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'deletelabelpic.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
	<script>
				function prochange(){
		     		var proid= $("#productselect").val();
		     		if(proid=="xx"){
		     					document.getElementById("label").length=0;
								var o=document.createElement("option");
								o.innerHTML="--请选择款式--";
						    	o.setAttribute("value","yy");
						    	document.getElementById("label").appendChild(o);
						    	$("#showpicdiv").html("");
		     		}else{
		     					$.getJSON("getLabelByProductIdAction",{"productId":proid},function(data){
								if(data.labels.length>0){
									document.getElementById("label").length=0;
									var o=document.createElement("option");
							    	o.innerHTML="--请选择款式--";
							    	o.setAttribute("value","0000");
							    	document.getElementById("label").appendChild(o);
					    			$.each(data.labels,function(index,value){
						    			var o=document.createElement("option");
								    	o.innerHTML=value.labelName+"";
								    	o.setAttribute("value",value.labelId);
								    	document.getElementById("label").appendChild(o); 
			    					});
								}else{
									document.getElementById("label").length=0;
									var o=document.createElement("option");
									o.innerHTML="--未上传款式--";
							    	o.setAttribute("value","0000");
							    	document.getElementById("label").appendChild(o);
								}
					});	     
						$.getJSON("getAllPicByProductIdAction",{"productId":proid},function(data){
										//alert(data.pic.length);
								if(data.pic.length>0){
										$("#showpicdiv").html("");
										$.each(data.pic,function(index,value){
												$("#showpicdiv").append("<img src='"+value.picUrl+"' width=200px heigth=200px>");
												$("#showpicdiv").append("<a href='javascript:void(0);' onclick='deletepic(\""+value.picUrl+"\",1)' >删除</a>");
										});
										
								}else{
										$("#showpicdiv").html("该产品还没有型号");
								}
						});	
		     		
		     		}
	     	}
	     	function deletepic(picurl,flag){
		     	if(window.confirm("确定要删除么")){
		     	//alert(value.picUrl);
		     				$.post("deleteLabelPicByPicUrlAction",{"picUrl":picurl},function(data){
		     				if(data="success"){
		     					alert("删除成功");
		     					if(flag==1){
		     						prochange();
		     					}else if(flag==2){
		     						labelchange();
		     					}
		     				}else{
		     					alert("删除失败");
		     				}
		     		});
		     	}else{}
	     	}
				function labelchange(){
					var labelId=$("#label").val();
					if(labelId=="0000"){
						prochange();
					}else{
							$.getJSON("getPartPicByLabelIdAction",{"labelId":labelId},function(data){
							if(data.partPic.length>0){
								$("#showpicdiv").html("");
								$.each(data.partPic,function(index,value){
											//alert(value.picUrl);
												$("#showpicdiv").append("<img src='"+value.picUrl+"' width=200px heigth=200px>");
												$("#showpicdiv").append("<a href='javascript:void(0);' onclick='deletepic(\""+value.picUrl+"\",2)' >删除</a>");
								});
							}else{
								$("#showpicdiv").html("该系列暂无图片");
							}
					});
					}
					//alert(labelId);
				}
	</script>
  </head>
  
  <body>
  		<div align="center"><h2>删除款式图片</h2></div>
   		<div  align="center">
			<select name="product"  id="productselect" style="width: 135px;" onchange="prochange()">
				<option value="xx">--请选择产品--</option>
				<c:forEach items="${product}" var="pro">
					<option value="${pro.productId}">${pro.productName}</option>
				</c:forEach>
			</select>
			<select name="label"  id="label" style="width: 135px;" onchange="labelchange()">
				<option value="yy">--请选择款式--</option>
			</select>
		</div>
		<div align="center" id="showpicdiv"></div>
  </body>
</html>
